package com.hsav.kcxb.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.provider.ContactsContract;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.hsav.kcxb.R;
import com.hsav.kcxb.activity.SettingActivity;
import com.hsav.kcxb.adapter.AttentionAdapter;
import com.hsav.kcxb.bean.AttentionBean;
import com.kcbsdk.AFetchType;
import com.kcbsdk.MyTools.ACloudType;
import com.kcbsdk.MyTools.AUiPageName;

import java.io.File;
import java.util.ArrayList;

import static com.hsav.kcxb.main.MSYS.mMyTools;

/**
 * Created by zhao on 16-12-9.
 */

public class FindsFragment extends Fragment {
    private static final String TAG = FindsFragment.class.getSimpleName();
    private SearchView mSearchView;
    private ListView mFriendLv;
    private ImageView mSettingImg;
    private TextView mTitleTx;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.i(TAG,"container:"+container);
        View rootView = inflater.inflate(R.layout.frag_find_layout,container,false);
        initView(rootView);
        return rootView;
    }
    public void OnShowWindow(Activity activity, boolean show){
        if (show){

            boolean pathExist = false;
            boolean pathCreate = false;
            File file;

            String appName = getString(R.string.appEnName);
            String gsFilePath = "";
            if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) == true)	{
                // 判断SDCard是否存在 [当没有外挂SD卡时，内置ROM也被识别为存在sd卡]
                gsFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
                file = new File(gsFilePath);
                pathExist = file.exists();
                if (!pathExist)
                {
                    pathCreate = file.mkdirs();
                }
                pathExist = file.exists();
            }
            if (!pathExist && !pathCreate)	{
              //  gsFilePath = getApplicationContext().getFilesDir() + "/" + appName + "/";
            }
if(pathExist){
    mMyTools.Log("searchLocalSpecFileDbs "+gsFilePath);
//    mMyTools.searchLocalSpecFileDbs(AFetchType.LIST_FRESHEN, gsFilePath, "mp3");
}

        }
    }

    private void initView(View rootView) {
        mSettingImg = (ImageView)rootView.findViewById(R.id.iv_top_back);
        mSettingImg.setImageResource(R.drawable.setting);
        mSettingImg.setVisibility(View.VISIBLE);
        mSettingImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), SettingActivity.class);
                startActivity(intent);
            }
        });

        mTitleTx = (TextView)rootView.findViewById(R.id.tv_top_title);
        mTitleTx.setText("发现");

        mSearchView = (SearchView)rootView.findViewById(R.id.search_find_view);
        mSearchView.setSubmitButtonEnabled(true);
        mSearchView.setIconifiedByDefault(false);
        mSearchView.setQueryHint("找好友（名字，ID等");

        mFriendLv = (ListView)rootView.findViewById(R.id.list_find_friend);
        ArrayList<AttentionBean> attenList = new ArrayList<>();
        attenList.add(new AttentionBean("","zhao","ahha","src",true));
        attenList.add(new AttentionBean("tain","lal","ll","dsfd",false));
        attenList.add(new AttentionBean("","zhao","ahha","src",true));
        attenList.add(new AttentionBean("tain","lal","ll","dsfd",false));
        attenList.add(new AttentionBean("","zhao","ahha","src",true));
        attenList.add(new AttentionBean("tain","lal","ll","dsfd",false));
        attenList.add(new AttentionBean("","zhao","ahha","src",true));
        attenList.add(new AttentionBean("tain","lal","ll","dsfd",false));

        AttentionAdapter attentionAdapter = new AttentionAdapter(getActivity(),attenList,true);
        mFriendLv.setAdapter(attentionAdapter);
    }
}
